import mysql from "mysql2";
import config from "./config.ts";

const connections = mysql.createPool({
  host: config.MYSQL_HOST,
  port: Number(config.MYSQL_PORT),
  database: config.MYSQL_DATABASE,
  user: config.MYSQL_USER,
  password: config.MYSQL_PASSWORD,
  trace: true, // 启用详细日志
});

connections.getConnection((err, conn) => {
  conn.connect((err) => {
    if (err) {
      console.log("连接失败:", err);
    } else {
      console.log("数据库连接成功 !!");
      conn.release(); // 归还连接到池子
    }
  });
});

export default connections.promise();
